<hr style="margin:0 0 1em;"/>

<!-- container with left & right sections start -->

<div class="wrapper">
	<div class="col-md-12 pt-20">
<?php
		$this->widget('zii.widgets.CBreadcrumbs', array(
	    	'links'=>array('Search'),
		));
?>
</div>
<div class="clearfix"></div>
	<div class="col-md-12 pb-50">
	<br><p>Search result for: <strong><?php echo $keyword?></strong>
	<!-- Left column starts -->
	
		<div class="col-md-8 mt-20 main-left-content row">
			<?php 
				$titles = array_keys($ids);
				$slugs = array_values($ids);
			?>
			<ul class="search-results">
			<?php for($i=0;$i<count($ids);$i++): ?>
				<li>
				<a href="<?php echo $this->createurl('site/page',array('slug'=>$slugs[$i]));?>"><?php echo $titles[$i]?></a>
				<p class="url"><a href="<?php echo $this->createurl('site/page',array('slug'=>$slugs[$i]));?>"><?php echo $this->createurl('site/page',array('slug'=>$slugs[$i]));?></a></p>
				<p><?php echo substr(strip_tags(htmlspecialchars_decode($contents[$i])),0,200).'...'?></p>
				</li>
			<?php endfor;?>
			</ul>
			
			<?php if (count($ids) > 5):?>
			<div class="col-md-12 text-center">
				<ul class="pagination">
				<?php for($i=0;$i< ceil((count($ids))/5); $i++):?>
					<li><a href="javascript:void(0)" data-page="<?php echo $i+1?>"><?php echo $i+1?></a></li>
				<?php endfor;?>
				
				</ul>
			</div>
			<?php endif;?>
			
			
		</div>
		
		<!-- Left column Ends -->
		
		
		<!-- right column starts -->
		
			<?php $this->renderPartial('site/_rightbar')?>
			
		<!-- right column Ends -->
	</div>
	
</div>
	<div class="clearfix"></div>
	<div class="clearfix"></div>
	
<!-- 3 blocks sectino with image starts  -->
		<?php $this->renderPartial('site/_blocks');?>
<!-- 3 blocks sectino with image Ends -->

	<div class="clearfix"></div>
	
	<!--  Newsletter section starts -->
		<?php $this->renderPartial('site/_newsletter');?>
	<!--  Newsletter section ends -->
<script>

jQuery.fn.highlight = function(pat) {
	 function innerHighlight(node, pat) {
	  var skip = 0;
	  if (node.nodeType == 3) {
	   var pos = node.data.toUpperCase().indexOf(pat);
	   if (pos >= 0) {
	    var spannode = document.createElement('span');
	    spannode.className = 'highlight';
	    var middlebit = node.splitText(pos);
	    var endbit = middlebit.splitText(pat.length);
	    var middleclone = middlebit.cloneNode(true);
	    spannode.appendChild(middleclone);
	    middlebit.parentNode.replaceChild(spannode, middlebit);
	    skip = 1;
	   }
	  }
	  else if (node.nodeType == 1 && node.childNodes && !/(script|style)/i.test(node.tagName)) {
	   for (var i = 0; i < node.childNodes.length; ++i) {
	    i += innerHighlight(node.childNodes[i], pat);
	   }
	  }
	  return skip;
	 }
	 return this.length && pat && pat.length ? this.each(function() {
	  innerHighlight(this, pat.toUpperCase());
	 }) : this;
	};

	jQuery.fn.removeHighlight = function() {
	 return this.find("span.highlight").each(function() {
	  this.parentNode.firstChild.nodeName;
	  with (this.parentNode) {
	   replaceChild(this.firstChild, this);
	   normalize();
	  }
	 }).end();
	};
	
$(document).ready(function(){
	$('.search-results li p').highlight("<?php echo $keyword?>");

	$('ul.search-results li:gt(4)').hide();
	$('ul.pagination li:eq(0)').addClass('active');

	$('ul.pagination li a').on('click', function(){
		page = $(this).data('page');
		size = 4;
		endPage = (size * page) + page;
		startPage = endPage - size;
		$('ul.search-results li').hide().slice(startPage, endPage).show();
		$('ul.pagination li').removeClass('active');
		$(this).parent().addClass('active');
		$('html,body').animate({scrollTop: 200}, 1000);
	});
	
});
</script>